package com.smallA.controller;

import com.smallA.constant.AccessConstant;
import com.smallA.service.ExamQuestionService;
import com.smallA.service.GradeService;
import org.springframework.security.access.annotation.Secured;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * 获取考试对应信息控制器类
 */
@Controller
public class ExamineController {

    private GradeService gradeService;
    private ExamQuestionService examQuestionService;

    public void setExamQuestionService(ExamQuestionService examQuestionService) {
        this.examQuestionService = examQuestionService;
    }

    public void setGradeService(GradeService gradeService) {
        this.gradeService = gradeService;
    }


    @ResponseBody
    @RequestMapping("/Examine/getExam")
    @Secured(AccessConstant.STUDENT_ACCESS)
    public Object getExam(int eid) {
        Map<String, Object> map = examQuestionService.selectExamById(eid);
        return map;
    }

    @RequestMapping("/Examine/getQuestion")
    @ResponseBody
    public Object getQuestion(){
//        model.addAttribute("Question",examQuestionService.selectAllQuestion());
//         return "teacher/question";
        Map<String,Object> map = new HashMap<>();
        map.put("Question",examQuestionService.selectAllQuestion());
        return map;
    }


    @RequestMapping("/Examine/add")
    @ResponseBody
    public Object addExam(Integer[] choice, Integer[] fill, Integer[] shortAnswer, String analyze, int score,int tid){

//        Client user = (Client) request.getSession().getAttribute(DataConstant.STUDENT_USER);
//        String[] choices = request.getParameterValues("choice");
//        String[] fills = request.getParameterValues("fill");
//        String[] shortAnswers = request.getParameterValues("shortAnswer");
//        String analyze = request.getParameter("analyze");
//        Integer score = Integer.valueOf(request.getParameter("score"));
        return examQuestionService.addExam(tid,analyze,choice,fill,shortAnswer,score);

    }
}
